﻿
using System.Text;

namespace SqlFormat.Rtf {
    public class RtfSqlFormatter : SqlFormatter<RtfSqlFormatterOptions> {
        private readonly int _stringColorIndex = 1;
        private readonly int _keyWordColorIndex = 2;

        public RtfSqlFormatter(RtfSqlFormatterOptions sqlFormatterOptions)
            : base(sqlFormatterOptions) {
        }

        public override string Format(string sql) {
            StringBuilder sb = new StringBuilder();

            sb.AppendLine("{\\rtf1\\ansi");
            // cf1 - strings
            // cf2 - keywords
            // cf3 - comments
            sb.AppendLine("{\\colortbl ;\\red163\\green21\\blue21;\\red0\\green0\\blue255;\\red0\\green128\\blue0;}");
            sb.Append(base.Format(sql));
            sb.AppendLine("\\pard");
            sb.AppendLine("}");

            return sb.ToString();
        }

        protected override string BeforeString {
            get { return string.Format("\\cf{0} ", _stringColorIndex); }
        }

        protected override string AfterString {
            get { return "\\cf0 "; }
        }

        protected override string BeforeKeyWordString {
            get { return string.Format("\\cf{0} ", _keyWordColorIndex); }
        }

        protected override string AfterKeyWordString {
            get { return "\\cf0 "; }
        }

        protected override string NewLineString {
            get { return string.Format("\\par\n\\li{0} ", Indent * 180); }
        }
    }
}
